package validation;

import java.text.SimpleDateFormat;
import java.util.Date;


import dbmanager.DBManager;

public class Lt implements Validation
{
	String ConditionValue;
	public boolean validate (String Value, String ConditionValue)
	{
		try 
		{
			double val = Double.parseDouble(Value);
			double convalue = Double.parseDouble(ConditionValue);
			
			if (val < convalue)
			{
				return true;
			}
			else
				return false;
		} 
		catch (NumberFormatException e) 
		{
			//STRING
		try
			{
				if(Value.length()==ConditionValue.length())
				{
					String pattern = "yyyy-MM-dd HH:MM:ss";
					SimpleDateFormat sdm = new SimpleDateFormat(pattern);
					Date date_value;
					try 
					{
						date_value = (Date)sdm.parse(Value);
					}
					catch (Exception e1) {
						Value = Value+" 00:00:00";
						date_value = (Date)sdm.parse(Value);
					}
					
					Date date_condition;
					try
					{
						date_condition = (Date)sdm.parse(ConditionValue);
					} catch (Exception e1) {
						ConditionValue = ConditionValue+" 00:00:00";
						date_condition = (Date)sdm.parse(ConditionValue);
					}
					
					if(date_value.compareTo(date_condition)<0)
						return true;
					else
						return false;
				}
				else
				{
					String pattern = "yyyy-MM-dd";
					SimpleDateFormat sdm = new SimpleDateFormat(pattern);
					Date date_value = (Date)sdm.parse(Value);
					Date date_condition = (Date)sdm.parse(ConditionValue);
					
					if(date_value.compareTo(date_condition)<0)
						return true;
					else
						return false;
				}
			}
			catch (Exception e1) 
			{
				e.printStackTrace();
			}
		}
		return false;
	}
	
	public boolean validate(String Value) 
	{	
		return false;
	}
	public String getMessage() 
	{
		return "The value must be Less than "+ConditionValue;
	}
	
	public static void main (String args[])
	{
		Lt lt = new Lt();
		System.out.println("Validate : "+lt.validate("178", "100"));
		System.out.println("Validate : "+lt.validate("12", "100"));
		System.out.println("Validate : "+lt.validate("100", "100"));
		System.out.println("Validate : "+lt.validate("2006-06-11 00:00:00", "2006-06-11 00:00:00"));
		//System.out.println("Validate : "+lt.validate("1985/11/01", "1985/12/01"));
	}

	public void setDbmanager(DBManager database) 
	{	
	}

	public boolean validate(String Value, String ConditionValue, String Refvalue) 
	{
		this.ConditionValue = ConditionValue;
		return validate(Value, ConditionValue);
	}

	public void setBasicvalue(String value) {
		// TODO Auto-generated method stub
		
	}
}
